<script lang="ts" setup>
import { getDepAllAPI } from '@/apis/consult'
import type { DepartmentItem } from '@/types/consult'
import { computed, ref } from 'vue'

// 所有科室列表
const depList = ref<DepartmentItem[]>([])

// 获取所有科室
const getDepAll = async () => {
  const res = await getDepAllAPI()
  depList.value = res.data
}

// 调用获取所有科室
getDepAll()

// 选中科室
const activeIndex = ref(0)

// 选中科室的子级
const activeDepChild = computed(() => {
  return depList.value[activeIndex.value]?.child
})

//获取分布表单的页面参数
const props = defineProps<{
  type: string
  illnessType: string
}>()

</script>

<template>
  <view class="department-page">
    <scroll-view scroll-y class="department-primary">
      <!-- 一级科室 -->
      <view 
      v-for="(item, index) in depList" 
      :key="item.id"
      @click="activeIndex = index"
      :class="{ active: activeIndex === index }"
      class="department-item"
      >{{ item.name }}</view>
    </scroll-view>

    <scroll-view class="department-secondary">
      <navigator
      hover-class="none"
        class="department-item"
        v-for="item in activeDepChild"
        :key="item.id"
        :url="`/subpkg_consult/pages/description/description?depId=${item.id}&type=${props.type}&illnessType=${props.illnessType}`"
      >
        {{ item.name }}
      </navigator>
    </scroll-view>
  </view>
</template>

<style lang="scss">
@import './index.scss';
</style>